package com.tc.travel.util;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class HtmlUtil {
	public static void main(String[] args) {
		Document doc = Jsoup.parse("<td rowspan=\"3\" style=\"text-align:center;\">\r\n"
				+ "							<a href=\"identity_info.php?IDENTITY_ID=3430526\">P7BJ98S-1</a>\r\n"
				+ "							<div class=\"icon sousin\">発行済</div>\r\n"
				+ "														<div class=\"icon	 grayicon\">帰国報告</div>							<div class=\"icon grayicon\">提出状況</div>							<div class=\"icon grayicon\">事故報告</div>						</td>");

		Elements links = doc.select(":containsOwn(P7BJ98S-1)");
		for (Element link : links) {
			String href = link.attr("href");
			System.out.println(href.substring(href.indexOf("IDENTITY_ID=") + "IDENTITY_ID=".length()));
		}
	}

	public static String getPageKey(String html) {
		Document doc = Jsoup.parse(html);
		Elements links = doc.select("input[name=_PAGE_KEY]");
		for (Element link : links) {
			String value = link.attr("value");
			if (!StringUtil.isEmpty(value)) {
				return value;
			}
		}

		return null;
	}

	public static String getDestVisaId(String html) {
		Document doc = Jsoup.parse(html);
		Elements links = doc.select("div.note > h3");
		for (Element link : links) {
			if (link.text() != null && link.text().indexOf("受付番号：") >= 0) {
				return link.text().substring(link.text().indexOf("受付番号：") + "受付番号：".length()).trim();
			}
		}

		return null;
	}
}
